package edu.nf.admin.controller.admin;

import edu.nf.waimai.dao.admin.impl.UserDaoImpl;
import edu.nf.waimai.model.user.User;
import org.nf.web.annotation.Model;
import org.nf.web.annotation.RequestMapping;
import org.nf.web.annotation.RequestParam;
import org.nf.web.servlet.View;
import org.nf.web.servlet.view.JsonView;

import java.util.List;

/**
 * @Date 2023-09-12
 * @Author qiu
 * 用户信息管理
 */
public class UserInfoController extends BaseController {

    /**
     * 用户信息 -- 管理员端
     *
     * @return
     */
    @RequestMapping("/user/userInfo")
    public View getAllUser() {
        List<User> list = new UserDaoImpl().getAllUser();

        return new JsonView(success(list));
    }

    /**
     * 用户修改
     *
     * @param user
     * @return
     */
    @RequestMapping("/user/updateUser")
    public View updateUser(@Model User user) {
        int i = new UserDaoImpl().updateUser(user);
        return new JsonView(success(200, "修改成功", i));
    }

    /**
     * 删除用户
     *
     * @param uid
     * @return
     */
    @RequestMapping("/user/deleteUser")
    public View deleteUser(@RequestParam("userId") int uid) {
        int i = new UserDaoImpl().deleteUser(uid);
        return new JsonView(success(200, "删除成功", i));
    }

    /**
     * 添加用户
     *
     * @param user
     * @return
     */
    @RequestMapping("/user/addUser")
    public View addUser(@Model User user) {
        int i = new UserDaoImpl().addUser(user);
        return new JsonView(success(200, "添加成功", i));
    }

    /**
     * 查询用户订单信息
     *
     * @return
     */
    @RequestMapping("/user/getUsser")
    public View getUser() {
        List<User> user = new UserDaoImpl().getUser();
        return new JsonView(success(user));
    }

}
